document.addEventListener('DOMContentLoaded', function (event) {
    const submitForm=document.getElementById('author-apply');
    const fieldName=document.getElementById('field-name1');
    const errorMessage = document.getElementById('errorMessage');
    const errorMessage1 = document.getElementById('errorMessage1');
    const errorMessage2 = document.getElementById('errorMessage2');
    const errorMessage3 = document.getElementById('errorMessage3');
    const errorMessage4 = document.getElementById('errorMessage4');
    const authorIntroduction=document.getElementById('author-introduction');
    const articleIntroduction=document.getElementById('article-introduction');
    const phonenumber=document.getElementById('phonenumber')
    submitForm.addEventListener('submit',function(event){
        const fieldNameInput=fieldName.value;
        const authorIntroductionInput=authorIntroduction.value;
        const articleIntroductionInput=articleIntroduction.value;
        const phonenumberInput=phonenumber.value;
        if (fieldNameInput.length===0 ||authorIntroductionInput.length===0
            || articleIntroductionInput.length===0 || phonenumberInput.length===0){
            event.preventDefault();
            alert('请检查带*的项目是否填写完毕');
        }
    });
    fieldName.addEventListener('blur',function(){
        if (fieldName.value === '') {
            errorMessage.style.display = 'inline';
        } else {
            errorMessage.style.display = 'none';
        }
    });
    fieldName.addEventListener('focus', function () {
        errorMessage.style.display = 'none';
    });
    authorIntroduction.addEventListener('blur',function(){
        if (fieldName.value === '') {
            errorMessage1.style.display = 'inline';
        } else {
            errorMessage1.style.display = 'none';
        }
    });
    authorIntroduction.addEventListener('focus', function () {
        errorMessage1.style.display = 'none';
    });
    article.addEventListener('blur',function(){
        if (fieldName.value === '') {
            errorMessage2.style.display = 'inline'; // 显示提示信息
        } else {
            errorMessage2.style.display = 'none'; // 输入框有值，隐藏提示信息
        }
    });
    article.addEventListener('focus', function () {
        errorMessage2.style.display = 'none'; // 输入框获得焦点时隐藏提示信息
    });
    articleIntroduction.addEventListener('blur',function(){
        if (fieldName.value === '') {
            errorMessage3.style.display = 'inline'; // 显示提示信息
        } else {
            errorMessage3.style.display = 'none'; // 输入框有值，隐藏提示信息
        }
    });
    articleIntroduction.addEventListener('focus', function () {
        errorMessage3.style.display = 'none'; // 输入框获得焦点时隐藏提示信息
    });
    phonenumber.addEventListener('blur',function(){
        if (fieldName.value === '') {
            errorMessage4.style.display = 'inline'; // 显示提示信息
        } else {
            errorMessage4.style.display = 'none'; // 输入框有值，隐藏提示信息
        }
    });
    phonenumber.addEventListener('focus', function () {
        errorMessage4.style.display = 'none'; // 输入框获得焦点时隐藏提示信息
    });
})